package com.arpa.oms.controller;

import cn.hutool.core.collection.IterUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.StrUtil;
import com.arpa.core.web.MediaTypes;
import com.arpa.core.web.Result;
import com.arpa.ntocc.common.common.Page;
import com.arpa.ntocc.common.common.constant.StrConsts;
import com.arpa.ntocc.common.common.util.UserUtil;
import com.arpa.ntocc.common.security.annotation.NeedLogin;
import com.arpa.wms.domain.consts.PropertyConst;
import com.arpa.wms.domain.consts.TipConst;
import com.arpa.wms.domain.dto.BrandDTO;
import com.arpa.wms.domain.entity.Brand;
import com.arpa.wms.domain.enums.StatusEnum;
import com.arpa.wms.domain.vo.BrandVO;
import com.arpa.wms.service.IBrandService;
import com.arpa.wms.service.IGoodsService;
import io.swagger.annotations.*;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;


/**
 * <p>
 * Oms品牌 Controller
 * </p>
 *
 * @author wangdong
 * @since 2021-07-21
 */
@Api(tags = "品牌")
@RestController
@RequestMapping(value="/omsBrand", produces = "application/json;charset=UTF-8")
@Log4j2
public class OmsBrandController {

   @Autowired
   private IBrandService  iBrandService;

   @Autowired
   private IGoodsService iGoodsService;

    /**
     * 获取 品牌 列表
     *
     * @param brandDTO
     * @param request
     * @return
     */
    @ApiOperation(value = "获取 品牌 列表", notes = "获取 品牌 列表")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "Authorization", value = "授权token", required = true, paramType = "header", dataType = "String", defaultValue = "Bearer "),
        @ApiImplicitParam(name = "deviceId", value = "设备id", paramType = "header", dataType = "string", defaultValue = "0000000000")
    })
    @ApiResponses(@ApiResponse(code = 0, message = "success", response = BrandVO.class))
    @NeedLogin
    @GetMapping
    public Result list(BrandDTO brandDTO,HttpServletRequest request) {
        try {
            brandDTO.setShipmentCode(UserUtil.getLoginWarehouseCodeOrShipmentCode());
            BrandVO brandVOSum = iBrandService.queryListSum(brandDTO);
            List<BrandVO> brandVOList = iBrandService.queryList(brandDTO);

            Page returnPage = new Page(brandDTO.getPageNum(),brandDTO.getPageSize());
            returnPage.setRecords(brandVOList);
            returnPage.setTotal(brandVOSum.getTotal());
            returnPage.setSumObject(brandVOSum);
            return Result.ok().data(returnPage);
        } catch (Exception e) {
            log.error(StrConsts.CATCH_MESSAGE,e);
            return Result.error(e.getMessage());
        }
    }



}
